package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.project.entity.FinanceProductInnerEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;
import com.yuexunit.util.DateUtil;

/**
*@version 创建时间：2016年10月31日 上午9:33:05
*@author NTBK-021-1006
*类说明
*/

@Implements(FinanceProductInnerService.class)
public class FinanceProductInnerServiceImpl implements FinanceProductInnerService {

	@Override
	@Transactional
	public Long createFinanceProductInner(FinanceProductInnerEntity entity) {
		entity.setCreateDateTime(DateUtil.now());
		entity.setUpdateDateTime(DateUtil.now());
		PersistUtil.insertOrUpdate(entity);
		return entity.getFinanceProductId();
	}

	@Override
	@Transactional
	public void updateFinanceProductInner(FinanceProductInnerEntity entity) {
		entity.setUpdateDateTime(DateUtil.now());
		PersistUtil.update(entity);
	}

	@Override
	public FinanceProductInnerEntity inquireFinanceProductInner(Long financeId, Long financeProductId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceProductInnerEntity.class);
		if (financeId != null) {
			criteria.add(Restrictions.eq("financeId", financeId));
		}
		if (financeProductId != null) {
			criteria.add(Restrictions.eq("financeProductId", financeProductId));
		}
		List<FinanceProductInnerEntity> list = PersistUtil.get(criteria);
		if (list.isEmpty()) {
			return null;
		}
		return list.get(0);
	}
}
